*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table 2: State level IRCA and district level compactness
*******************************

	//Load data
	use  state_irca_districts.dta, clear
		
	//Controls
	global state_controls c.state_pop1990#i.p102 c.income_state_pc1990#i.p102  c.age_share_state1990#i.p102 c.state_unemployment1990#i.p102 c.state_blackshare1990#i.p102 c.state_whiteshare1990#i.p102 c.state_births1990#i.p102 c.educ_state1990#i.p102 
								
	//Fixed Effects
	global fe  i.congress c.hisp_share_state1980#i.p102
	
	//VRA Control
	global vra_control i.vra_state#i.p102
	
	//Clustering
	global clusters StateFIPS
	
*********
* Report 
*********

eststo clear

//PP
	reghdfe pp $state_controls $vra_control $fe c.state_irca_total_pc_std##i.p102##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster($clusters)
	sum pp if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	boottest 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p_sum = r(p)
	eststo 
	
//Schwartzberg		
	reghdfe schw $state_controls $vra_control $fe c.state_irca_total_pc_std##i.p102##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster($clusters)
	sum schw if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	boottest 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p_sum = r(p)
	eststo 
	
//Reock
	reghdfe reock $state_controls $vra_control $fe c.state_irca_total_pc_std##i.p102##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster($clusters)
	sum reock if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	boottest 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p_sum = r(p)
	eststo 
	
//Convex-Hull
	reghdfe cvh $state_controls $vra_control $fe c.state_irca_total_pc_std##i.p102##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster($clusters)
	sum cvh if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	 boottest 1.p102#c.state_irca_total_pc_std + 1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p_sum = r(p)
	eststo 
	
	
***********************
*	Generate Table 
**********************		
estfe est*
esttab  est*	using "tab2.tex", replace booktabs ///
				nonote noobs nogaps compress noeqlines se substitute(_ _)  ///
				mtitles("Polsby-Popper" "Schwartzberg" "Reock" "Convex-Hull") ///
				scalars("N $N$" "clusters Clusters" "ymean $\bar{Y}_{102}$" "ysd $[S.D.]$" "boot_p2 IRCA x Post " "boot_p1 IRCA x Post x D") sfmt(%9.3gc) ///
				star(* 0.1 ** 0.05 *** 0.01) ///
				keep(1.p102#c.state_irca_total_pc_std  ///
					1.p102#1.legal_control_kaplan1991#c.state_irca_total_pc_std)	
					
					
					
